package com.xiu.travel.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author lijie
 * @date 2023/7/5 14:00
 * @description AmqpConfig
 */
@Configuration
public class AmqpConfig
{

    // 交换机名称
    public static final String ZJH_EXCHANGE_KEY = "zjh.exchange.pay";
//    public static final String ZJH_EXCHANGE_KEY = "test.zjh.exchange.pay";
//     队列名称（测试）
    public static final String ZJH_QUEUE_KEY = "zjh.order.pay";
//    public static final String ZJH_QUEUE_KEY = "test.zjh.order.pay";
    // 队列路线/绑定关系（测试）
    public static final String ZJH_ROUTK = "zjh.order.pay";
//    public static final String ZJH_ROUTK = "test.zjh.order.pay";


    @Bean
    public Queue zjhOrderQueue() {

        return new Queue(ZJH_QUEUE_KEY, true);
    }


    /**
     * 延时队列交换器
     *
     * @author lc
     * @date 2020/6/30 15:06
     */
    @Bean
    public CustomExchange zjhOrderExchange() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(ZJH_EXCHANGE_KEY, "x-delayed-message", true, false, args);
    }


    @Bean
    public Binding zjhOrderBinding(CustomExchange testExchange, Queue testQueue) {
        Binding binding = BindingBuilder.bind(testQueue).to(testExchange).with(ZJH_ROUTK).noargs();
        return binding;
    }
}
